﻿//using System.Linq;

//using System;
//using System.Collections.Generic;
//using System.Collections;

////---------------------------------------------- 对象和集合初始值设定项（C# 编程指南）
////class TestPerson
////{
////    public class Cat
////    {
////        // Auto-implemented properties.
////        public int Age { get; set; }
////        public string Name { get; set; }

////        public Cat()
////        {
////        }

////        public Cat(string name)
////        {
////            this.Name = name;
////        }

////        public double[,] MyDouble = new double[1,1];

////        // 索引器
////        public double this[int row, int column]
////        {
////            // The embedded array will throw out of range exceptions as appropriate.
////            get { return MyDouble[row, column]; }
////            set { MyDouble[row, column] = value; }
////        }

////    }
////    static void Main()
////    {
////        //对象设定项 
////        Cat cat = new Cat {
////            Name ="szq",
////            Age =11,
////            [0,0]=0,
////            [0, 1] = 1,
////            [1, 0] = 2,
////            [1, 1] = 3
////        };
////        Console.WriteLine("Press any key to exit.");
////        Console.ReadKey();
////    }
////}
////// Output:
////// George is 39
////// Charles is 41

////public class FullExample
////{
////    class FormattedAddresses : IEnumerable<string>
////    {
////        private List<string> internalList = new List<string>();
////        public IEnumerator<string> GetEnumerator() => internalList.GetEnumerator();

////        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => internalList.GetEnumerator();

////        public void Add(string firstname, string lastname,
////            string street, string city,
////            string state, string zipcode) => internalList.Add(
////            $@"{firstname} {lastname}
////                {street}
////                {city}, {state} {zipcode}"
////            );

////    }

////    public static void Main()
////    {
////        FormattedAddresses addresses = new FormattedAddresses()
////            {
////                {"John", "Doe", "123 Street", "Topeka", "KS", "00000" },
////                {"Jane", "Smith", "456 Street", "Topeka", "KS", "00000" }
////            };

////        Console.WriteLine("Address Entries:");

////        foreach (string addressEntry in addresses)
////        {
////            Console.WriteLine("\r\n" + addressEntry);
////        }
////    }

////    /*
////     * Prints:

////        Address Entries:

////        John Doe
////        123 Street
////        Topeka, KS 00000

////        Jane Smith
////        456 Street
////        Topeka, KS 00000
////     */
////}

////public class program
////{
////    public static void Main(String[] args)
////    {

////        Students students = new Students()
////        {

////            [0] = "A_Student",
////            ["0"] = "B_Student",
////            [2] = "C_Student",
////            [6] = "6_Student"

////        };
////        Console.WriteLine(students["B"]);
////        Console.WriteLine(students["6"]);
////        Console.ReadKey();


////    }
////}
////public class Students
////{

////    private IList<String> stuKeyList = new List<string>() { "0" };
////    private string[] stus = { "" };

////    private void ResetStus(int position)
////    {

////        if (stus.Length < position + 1)
////        {

////            Array.Resize(ref stus, position + 1);

////            stuKeyList = new List<string>() {};
////            for (int i = 0; i <= position; i++)
////                stuKeyList.Add(i.ToString());
////        }



////    }
////    public string this[int position]
////    {
////        get
////        {
////            if (position < 0) return "";

////            ResetStus(position);

////            return stus[position];
////        }
////        set
////        {
////            if (position < 0) return;

////            ResetStus(position);
////            stus[position] = value;
////        }
////    }
////    public string this[string key]
////    {
////        get => this[stuKeyList.IndexOf(key)];
////        set => this[stuKeyList.IndexOf(key)] = value;
////    }

////}

////---------------------------------------------- 对象和集合初始值设定项  如何使用集合初始值设定项初始化字典（C# 编程指南）

////public class HowToDictionaryInitializer
////{
////    class StudentName
////    {
////        public string FirstName { get; set; }
////        public string LastName { get; set; }
////        public int ID { get; set; }
////    }

////    public static void Main()
////    {
////        var students = new Dictionary<int, StudentName>()
////        {
////            { 111, new StudentName { FirstName="Sachin", LastName="Karnik", ID=211 } },
////            { 112, new StudentName { FirstName="Dina", LastName="Salimzianova", ID=317 } },
////            { 113, new StudentName { FirstName="Andy", LastName="Ruth", ID=198 } }
////        };

////        foreach (var index in Enumerable.Range(111, 3))
////        {
////            Console.WriteLine($"Student {index} is {students[index].FirstName} {students[index].LastName}");
////        }
////        Console.WriteLine();

////        var students2 = new Dictionary<int, StudentName>()
////        {
////            [111] = new StudentName { FirstName = "Sachin", LastName = "Karnik", ID = 211 },
////            [112] = new StudentName { FirstName = "Dina", LastName = "Salimzianova", ID = 317 },
////            [113] = new StudentName { FirstName = "Andy", LastName = "Ruth", ID = 198 }
////        };

////        foreach (var index in Enumerable.Range(111, 3))
////        {
////            Console.WriteLine($"Student {index} is {students2[index].FirstName} {students2[index].LastName}");
////        }
////    }
////}


//public class Student
//{
//    public string name { get; set; }
//    public int age { get; set; }

//}

//public class program
//{

//    public static void Main(string[] args)
//    {

//        IEnumerable<Student> enumerableStudents = new List<Student>{
//            new Student{name="szq",age=11 },
//            new Student{name="szq2",age=22 },
//             new Student{name="szq3",age=33 },
//             new Student{name="szq4",age=44 }
//        };
        

//        var result = from student in enumerableStudents
//                     where student.age > 22
//                     select student.name;

//        foreach (string name in result) {
//            Console.WriteLine(name);
//        }


//        var result2 = from student in enumerableStudents
//                     where student.age > 22
//                     select new { student.name,student.age };

//        foreach (var student in result2)
//        {
//            Console.WriteLine(student.name+student.age);
//        }

//        Console.ReadKey();

//    }

//}